﻿using System;
using System.Collections.Generic;
using System.Linq;
using GraphProcessor;
using IQIGame.Onigao.Logic;
using LFloatMath.Math;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(SkillEditorConst.SkillEffective + "/" + SkillEditorConst.Summon, typeof(SkillEditorGraph))]
    public class SkillEffectiveNode_Summon : SkillEffectiveNode
    {
        protected override ESkillEffectiveType effectType => ESkillEffectiveType.Summon;

        public SummonNodeData data;
        protected override SkillCustomConfig CreateConfig()
        {
            return data.ToConfig();
        }

        [Serializable]
        public class SummonNodeData
        {
            public int maxCount = 1;
            public int monsterID;
            public int power;
            public int powerType;
            public List<int> attrCorr;
            public List<SummonNodeAttrData> specialAttr = new List<SummonNodeAttrData>();
            public Node_V2 pos;

            public SkillCustomConfig ToConfig()
            {
                var rConfig = new SkillEffectiveAction_Summon_ConfigData()
                {
                    maxCount = this.maxCount,
                    monsterID = this.monsterID,
                    power = this.power,
                    powerType = this.powerType,
                    attrCorr = this.attrCorr,
                    specialAttr = this.specialAttr.Select((x) => x.ToEffectData()).ToList(),
                    posX = this.pos.x.ToLFloat()._val,
                    posY = this.pos.y.ToLFloat()._val,
                };
                return rConfig;
            }
        }

        [Serializable]
        public class SummonNodeAttrData
        {
            public EAttributeTypeFlag attrType;
            public float attrRate = 1;
            [Tooltip("@释放者 #被创建的单位")]public int formula;
            
            public SkillEffectiveAction_Summon_ConfigData.SummonAttrData ToEffectData()
            {
                return new SkillEffectiveAction_Summon_ConfigData.SummonAttrData()
                {
                    attrRate = this.attrRate.ToLFloat(),
                    attrType = this.attrType,
                    formula = this.formula
                };
            }
        }

        [Serializable]
        public struct Node_V2
        {
            public float x;
            public float y;
        }
    }
}